

/**
 * Arrs group by
 * @template T 
 * @param groupBy 
 * @param arr 
 * @returns group by 
 */
export function arrGroupBy<T>(groupBy: (item: T, index: number) => string, arr: T[]): { [key: string]: T[] } {
    const ret: { [key: string]: (T[]) } = {};
    arr.forEach((item, index) => {
        const key = groupBy(item, index);
        let items = ret[key];
        if (!items) ret[key] = items = [];
        items.push(item);
    });
    return ret;
}